import { ref, onMounted } from 'vue';
import { getSalesmanList } from '../api/system/user';

export function useYw() {
  const ywList = ref([]);
  const loading = ref(false);
  const error = ref<string | null>(null);

  const fetchYwList = async () => {
    loading.value = true;
    error.value = null;
    try {
      const res = await getSalesmanList();
      ywList.value = res.rows || [];
    } catch (e) {
      error.value = e.message || '获取业务员列表失败';
    } finally {
      loading.value = false;
    }
  };

  onMounted(fetchYwList);

  return {
    ywList,
    loading,
    error,
    fetchYwList
  };
}
